*****************************************************************
* Replication directory for                                   ***
* Prime locations                                             ***
* by Gabriel M. Ahlfeldt, Thilo N.H. Albers, Kristian Behrens ***
* Published in American Economic Review: Insights             ***
*****************************************************************
* 01/2025
* Stata
version 17.0

* This do files selects the outputs from the runs with the preferred p-value and copies them to the base folder



// Check the operating system and execute the corresponding commands
if "`c(os)'" == "Windows" {
	display "...Windows system detected..."
	display "...copying files..."
	// Save current content
	! copy /y "$figures_App\US-CBSAs\FIG_B1_1a_PctCutoff-log.pdf" "$temp\figures_App\US-CBSAs\p$SL"
	! copy /y "$figures_App\US-CBSAs\FIG_B1_1b_PctCutoff-log-top10.pdf" "$temp\figures_App\US-CBSAs\p$SL"
	// Remove existing directory
	shell rd /s /q "$figures/US-CBSAs"
	shell rd /s /q "$figures_App/US-CBSAs"
	shell rd /s /q "$tables_App/US-CBSAs"
	shell rd /s /q "$dataoutput/US-CBSAs" 
	// Gen folder for saving selected maps for Figure 1
	 capture  mkdir "$figures/US-CBSAs" 
	 capture  mkdir "$figures/US-CBSAs/Figure_1" 
    // Windows-specific commands
	shell xcopy "$temp/figures/US-CBSAs/p${SL}" "$figures/US-CBSAs" /E /I /H /Y				
	shell xcopy "$temp/figures_App/US-CBSAs/p${SL}" "$figures_App/US-CBSAs" /E /I /H /Y
	shell xcopy "$temp/tables/US-CBSAs/p${SL}" "$tables/US-CBSAs" /E /I /H /Y
	shell xcopy "$temp/tables_App/US-CBSAs/p${SL}" "$tables_App/US-CBSAs" /E /I /H /Y
	shell xcopy "$temp/US-CBSAs/p${SL}" "$dataoutput/US-CBSAs" /E /I /H /Y
}
else {
	display "...Mac/Linux system detected..."
	display "...copying files..."	
	// Save current content
	
	  shell cp -f "$figures_App/US-CBSAs/FIG_B1_1a_PctCutoff-log.pdf" "$temp/figures_App/US-CBSAs/p$SL"
	  shell cp -f "$figures_App/US-CBSAs/FIG_B1_1b_PctCutoff-log-top10.pdf" "$temp/figures_App/US-CBSAs/p$SL"

	
	
	* qui shell cp -f "$figures_App/US-CBSAs/FIG_B1_1a_PctCutoff-log.pdf" "$figures_App/US-CBSAs/FIG_B1_1b_PctCutoff-log-top10.pdf" "$temp/figures/US-CBSAs/p${SL}/"
	
	// Remove existing directory
	shell rm -rf "$figures/US-CBSAs"
	shell rm -rf "$figures_App/US-CBSAs"
	shell rm -rf "$tables_App/US-CBSAs"
	shell rm -rf "$dataoutput/US-CBSAs" 
	
	// Gen folder for saving selected maps for Figure 1
	 capture  mkdir "$figures/US-CBSAs" 
	 capture  mkdir "$figures/US-CBSAs/Figure_1" 
	 
    // Mac/Linux-specific commands
     shell cp -r "$temp/figures/US-CBSAs/p${SL}" "$figures/US-CBSAs"
     shell cp -r "$temp/figures_App/US-CBSAs/p${SL}" "$figures_App/US-CBSAs"
     shell cp -r "$temp/tables/US-CBSAs/p${SL}" "$tables/US-CBSAs"
	 shell cp -r "$temp/tables_App/US-CBSAs/p${SL}" "$tables_App/US-CBSAs"  
     shell cp -r  "$temp/US-CBSAs/p${SL}" "$dataoutput/US-CBSAs"
	
}
	// Copy additional file to Figure_1 folder
    shell cp -f "$figures_App/US-CBSAs/MAPS/MAPS_PL_TotalEmp_BaseP_16980.png" "$figures/US-CBSAs/Figure_1/"
    shell cp -f "$figures_App/US-CBSAs/MAPS/MAPS_PL_TotalEmp_BaseP_35620.png" "$figures/US-CBSAs/Figure_1/"
    shell cp -f "$figures_App/US-CBSAs/MAPS/MAPS_PL_TotalEmp_BaseP_31080.png" "$figures/US-CBSAs/Figure_1/"

	capture erase "$dataoutput/US-CBSAs/MSA_UsingData.dta"										// Only needed for further computations	} 
	
* Script ends
